package com.rahman.doctor;


import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Prescription extends Activity
{
	private Button b1, b2;
	private TextView t1, t2, t3, t4;
	private EditText e1, e2, e3, e4;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addpre);
        b1 = (Button)findViewById(R.id.btnPrescription);
        b2 = (Button)findViewById(R.id.btnClear);
        
        t1 = (TextView)findViewById(R.id.textView2);
        t2 = (TextView)findViewById(R.id.TextView01);
        t3 = (TextView)findViewById(R.id.TextView02);
        t4 = (TextView)findViewById(R.id.TextView03);
        
        e1 = (EditText)findViewById(R.id.txtClinic);
        e2 = (EditText)findViewById(R.id.txtPatient);
        e3 = (EditText)findViewById(R.id.txtIllness);
        e4 = (EditText)findViewById(R.id.txtDoctor);
        
        startBtnClickListener();
    }
    
    public void startBtnClickListener()
    {
    	b1.setOnClickListener(new View.OnClickListener()
    	{
    		public void onClick(View v)
    		{
    			GetInput();
    		}
    	});
    	
    	b2.setOnClickListener(new View.OnClickListener()
    	{
    		public void onClick(View v)
    		{
    			Clear();
    		}
    	});
    }
    
    public void Clear ()
    {
    	e1.setText("");
    	e2.setText("");
    	e3.setText("");
    	e4.setText("");
    	
    	t1.setTextColor(Color.WHITE);
    	t2.setTextColor(Color.WHITE);
    	t3.setTextColor(Color.WHITE);
    	t4.setTextColor(Color.WHITE);
    	
    }
    
    public void GetInput ()
    {    	
    	boolean b = CheckInput(t1, e1);
    	boolean bb = CheckInput(t2, e2);
    	boolean bbb = CheckInput(t3, e3);
    	boolean bbbb = CheckInput(t4, e4);
    	
    	if ((b) && (bb) && (bbb) && (bbbb))
    	{
    		PrescriptionClass p = new PrescriptionClass(e1.getText().toString(), e2.getText().toString(), e3.getText().toString(), e4.getText().toString());
    		PrescriptionMethods.CreatePrescription(p);   		
    		//Toast.makeText(getApplicationContext(), p.getDoctorName(), Toast.LENGTH_LONG).show();
			Intent i = new Intent(Prescription.this, AddMedicine.class);
	        startActivity(i);
    	}
    }
    
    public boolean CheckInput(TextView t, EditText e)
    {
    	if (!(e.getText().toString().equals("")))
    	{
    		t.setTextColor(Color.WHITE);
    		return true;
    	}
    	else
    	{
    		t.setTextColor(Color.RED);
    		return false;
    	}
    }
}
